<!--#Include File="Include.asp"--><%
'--------------------------------------
'Power By 方卡在线 @2010-2014 f02
'URL:http://www.fangka.net/
'EMail:admin@ifangka.com
'QQ:861118936
'版权所有 未经允许不得去除本版权信息
'--------------------------------------

Call CheckAdminType("0,1",UType)
Call CheckAdminLimit(ULimit,"o_Vote",0)

Dim Fk_Vote_Name,Fk_Vote_Content,Fk_Vote_Ticket
Dim Vote_Record,Vote_Ticket

Types=Clng(Request.QueryString("Type"))

Select Case Types
	Case 1
		Call VoteList() '投票列表
	Case 2
		Call VoteAddForm() '添加投票表单
	Case 3
		Call VoteAddDo() '执行添加投票
	Case 4
		Call VoteEditForm() '修改投票表单
	Case 5
		Call VoteEditDo() '执行修改投票
	Case 6
		Call VoteDelDo() '执行删除投票
	Case 7
		Call VoteLabel() '获取轮换调用代码
	Case Else
		Call FKFun.ShowErr("未发现功能项！",1)
End Select

'==========================================
'函 数 名：VoteList()
'作    用：投票列表
'==========================================
Sub VoteList()
%>
		<div id="rightNav">
			<ul>
				<li><a href="Vote.asp?Type=2" target="dialog" width="900">添加投票</a></li>
			</ul>
		</div>
		<div id="searchLine" class="font_bold">
			投票管理
		</div>
		<table width="100%" bordercolor="#CCCCCC" border="1" cellspacing="0" cellpadding="0">
			<tr>
				<th align="center">ID</th>
				<th align="center">名称</th>
				<th align="center">投票数量</th>
				<th align="center">操作</th>
			</tr>
<%
	Sqlstr="Select Fk_Vote_Id,Fk_Vote_Name,Fk_Vote_Ticket From [Fk_Vote] Order By Fk_Vote_Id Asc"
	Rs.Open Sqlstr,Conn,1,1
	If Not Rs.Eof Then
		i=1
		While Not Rs.Eof
%>
			<tr>
				<td height="20" align="center"><%=i%></td>
				<td>&nbsp;<%=Rs("Fk_Vote_Name")%></td>
				<td align="center"><%=Rs("Fk_Vote_Ticket")%></td>
				<td align="center"><a href="Vote.asp?Type=7&Id=<%=Rs("Fk_Vote_Id")%>" target="dialog" width="900">调用代码</a> <a href="Vote.asp?Type=4&Id=<%=Rs("Fk_Vote_Id")%>" target="dialog" width="900">修改</a> <a href="Vote.asp?Type=6&Id=<%=Rs("Fk_Vote_Id")%>" target="delete" confirmStr="您确认要删除“<%=Rs("Fk_Vote_Name")%>”？此操作不可逆！" refreshUrl="Vote.asp?Type=1" showStr="名称删除成功！">删除</a></td>
			</tr>
<%
			Rs.MoveNext
			i=i+1
		Wend
	Else
%>
			<tr>
				<td height="25" colspan="20" align="center">暂无记录</td>
			</tr>
<%
	End If
	Rs.Close
%>
			<tr>
				<td height="30" colspan="20">&nbsp;</td>
			</tr>
		</table>
		<div id="rightBottom">
		
		</div>
<%
End Sub

'==========================================
'函 数 名：VoteAddForm()
'作    用：添加投票表单
'==========================================
Sub VoteAddForm()
%>
<form id="VoteAdd" name="VoteAdd" method="post" target="ajax" action="Vote.asp?Type=3" showStr="新投票添加成功！" refreshUrl="Vote.asp?Type=1" boxClose="1">
<div id="title">添加新投票</div>
<div id="box">
	<table width="90%" border="1" bordercolor="#CCCCCC" align="center" cellpadding="0" cellspacing="0">
		<tr>
			<td width="10%" height="30" align="right">名称：</td>
			<td width="90%">&nbsp;<input name="Fk_Vote_Name" type="text" class="input" id="Fk_Vote_Name" /><span class="help" title="<p>投票名称，请输入1-50个字符（两个字符为一个汉字）。</p>"></span></td>
		</tr>
		<tr>
			<td height="30" align="right">投票次数：</td>
			<td>&nbsp;<input name="Fk_Vote_Ticket" type="text" class="input" id="Fk_Vote_Ticket" value="0" /><span class="help" title="<p>投票次数，必须是数字。</p>"></span></td>
		</tr>
	</table>
	<p id="VoteList">&nbsp;</p>
	<table width="90%" border="1" bordercolor="#CCCCCC" align="center" cellpadding="0" cellspacing="0">
	    <tr>
	        <td height="30" width="10%" align="right">投票项：</td>
	        <td width="40%">&nbsp;<input name="Vote_Record" type="text" class="input" id="Vote_Record" size="40" /><span class="help" title="<p>投票项，请输入1-50个字符（两个字符为一个汉字）。</p>"></span></td>
	        <td width="10%" align="right">投票数：</td>
	        <td width="40%">&nbsp;<input name="Vote_Ticket" type="text" class="input" id="Vote_Ticket" value="0" size="4" /><span class="help" title="<p>票数，必须是数字。</p>"></span></td>
	    </tr>
        <tr>
            <td height="30" align="right">&nbsp;</td>
            <td colspan="3">&nbsp;<input type="button" class="button" name="btn1" id="btn1" value="增加" onclick="AddVote();" /></td>
        </tr>
	</table>
</div>
<div id="bottom">
	<input type="submit" class="button" name="Enter" id="Enter" value="添 加" />
	<input type="button" onclick="dialogClose();" class="button" name="button" id="button" value="关 闭" />
</div>
</form>
<%
End Sub

'==============================
'函 数 名：VoteAddDo
'作    用：执行添加投票
'==============================
Sub VoteAddDo()
	Fk_Vote_Name=FKFun.HTMLEncode(Trim(Request.Form("Fk_Vote_Name")))
	Fk_Vote_Content=FKFun.HTMLEncode(Trim(Replace(Request.Form("Fk_Vote_Content"),", ","")))
	Fk_Vote_Ticket=Trim(Request.Form("Fk_Vote_Ticket"))	
	Call FKFun.JsonString(Fk_Vote_Name,1,50,0,"请输入名称！","名称不能大于50个字符！")
	Call FKFun.JsonString(Fk_Vote_Content,1,50,1,"请增加轮换项！","内容不能大于50个字符！")
	Call FKFun.JsonNum(Fk_Vote_Ticket,"投票次数必须是数字！")
	Sqlstr="Select Fk_Vote_Id,Fk_Vote_Name,Fk_Vote_Content,Fk_Vote_Ticket From [Fk_Vote] Where Fk_Vote_Name='"&Fk_Vote_Name&"'"
	Rs.Open Sqlstr,Conn,1,3
	If Rs.Eof Then
		Application.Lock()
		Rs.AddNew()
		Rs("Fk_Vote_Name")=Fk_Vote_Name
		Rs("Fk_Vote_Content")=Fk_Vote_Content
		Rs("Fk_Vote_Ticket")=Fk_Vote_Ticket
		Rs.Update()
		Application.UnLock()
		Call FKFun.JsonSuccess()
	Else
		Rs.Close
		Call FKFun.JsonError("该投票名称已经被占用！")
	End If
	Rs.Close
End Sub

'==========================================
'函 数 名：VoteEditForm()
'作    用：修改投票表单
'==========================================
Sub VoteEditForm()
	Id=Clng(Request.QueryString("Id"))
	Sqlstr="Select Fk_Vote_Name,Fk_Vote_Content,Fk_Vote_Ticket From [Fk_Vote] Where Fk_Vote_Id=" & Id
	Rs.Open Sqlstr,Conn,1,1
	If Not Rs.Eof Then
		Fk_Vote_Name=Rs("Fk_Vote_Name")
		Fk_Vote_Content=Rs("Fk_Vote_Content")
		Fk_Vote_Ticket=Rs("Fk_Vote_Ticket")
	Else
		Rs.Close
		Call FKFun.ShowErr("投票不存在！",1)
	End If
	Rs.Close
%>
<form id="VoteEdit" name="VoteEdit" method="post" target="ajax" action="Vote.asp?Type=5" showStr="投票修改成功！" refreshUrl="Vote.asp?Type=1" boxClose="1">
<div id="title">修改投票</div>
<div id="box">
	<table width="90%" border="1" bordercolor="#CCCCCC" align="center" cellpadding="0" cellspacing="0">
		<tr>
			<td width="10%" height="30" align="right">名称：</td>
			<td width="90%">&nbsp;<input name="Fk_Vote_Name" type="text" class="input" id="Fk_Vote_Name" value="<%=Fk_Vote_Name%>" /><span class="help" title="<p>投票名称，请输入1-50个字符（两个字符为一个汉字）。</p>"></span></td>
		</tr>
		<tr>
			<td height="30" align="right">投票次数：</td>
			<td>&nbsp;<input name="Fk_Vote_Ticket" type="text" class="input" id="Fk_Vote_Ticket" value="<%=Fk_Vote_Ticket%>" /><span class="help" title="<p>投票次数，必须是数字。</p>"></span></td>
		</tr>
	</table>
<%
	TempArr=Split(Fk_Vote_Content,"|VoteList|")
	Response.Write("<script type=""text/javascript"">")
	For Each Temp In TempArr
		If Temp<>"" Then
			Vote_Record=FKFun.GetSub(Temp,"Vote_Record:","|;|","")
			Vote_Ticket=FKFun.GetSub(Temp,"Vote_Ticket:","|;|","")
			Response.Write("AddVote_Show('"&Vote_Record&"','"&Vote_Ticket&"');"&vbCrLf)
		End IF
	Next
	Response.Write("</script>")
%>
	<p id="VoteList">&nbsp;</p>
	<table width="90%" border="1" bordercolor="#CCCCCC" align="center" cellpadding="0" cellspacing="0">
	    <tr>
	        <td height="30" width="10%" align="right">投票项：</td>
	        <td width="40%">&nbsp;<input name="Vote_Record" type="text" class="input" id="Vote_Record" size="40" /><span class="help" title="<p>投票项，请输入1-50个字符（两个字符为一个汉字）。</p>"></span></td>
	        <td width="10%" align="right">投票数：</td>
	        <td width="40%">&nbsp;<input name="Vote_Ticket" type="text" class="input" id="Vote_Ticket" value="0" size="4" /><span class="help" title="<p>票数，必须是数字。</p>"></span></td>
	    </tr>
        <tr>
            <td height="30" align="right">&nbsp;</td>
            <td colspan="3">&nbsp;<input type="button" class="button" name="btn1" id="btn1" value="增加" onclick="AddVote();" /></td>
        </tr>
	</table>
</div>
<div id="bottom">
	<input type="hidden" name="Id" value="<%=Id%>" />
	<input type="submit" class="button" name="Enter" id="Enter" value="修 改" />
	<input type="button" onclick="dialogClose();" class="button" name="button" id="button" value="关 闭" />
</div>
</form>
<%
End Sub

'==============================
'函 数 名：VoteEditDo
'作    用：执行修改投票
'==============================
Sub VoteEditDo()
	Fk_Vote_Name=FKFun.HTMLEncode(Trim(Request.Form("Fk_Vote_Name")))
	Fk_Vote_Content=FKFun.HTMLEncode(Trim(Replace(Request.Form("Fk_Vote_Content"),", ","")))
	Fk_Vote_Ticket=Trim(Request.Form("Fk_Vote_Ticket"))	
	Id=Trim(Request.Form("Id"))
	Call FKFun.JsonString(Fk_Vote_Name,1,50,0,"请输入名称！","名称不能大于50个字符！")
	Call FKFun.JsonString(Fk_Vote_Content,1,50,1,"请增加轮换项！","内容不能大于50个字符！")
	Call FKFun.JsonNum(Fk_Vote_Ticket,"投票次数必须是数字！")
	Call FKFun.JsonNum(Id,"系统参数错误，请刷新页面！")
	Sqlstr="Select Fk_Vote_Id,Fk_Vote_Name,Fk_Vote_Content,Fk_Vote_Ticket From [Fk_Vote] Where Fk_Vote_Id=" & Id
	Rs.Open Sqlstr,Conn,1,3
	If Not Rs.Eof Then
		Application.Lock()
		Rs("Fk_Vote_Name")=Fk_Vote_Name
		Rs("Fk_Vote_Content")=Fk_Vote_Content
		Rs("Fk_Vote_Ticket")=Fk_Vote_Ticket
		Rs.Update()
		Application.UnLock()
		Call FKFun.JsonSuccess()
	Else
		Rs.Close
		Call FKFun.JsonError("要修改的投票不存在！")
	End If
	Rs.Close
End Sub

'==============================
'函 数 名：VoteDelDo
'作    用：执行删除投票
'==============================
Sub VoteDelDo()
	Id=Trim(Request.QueryString("Id"))
	Call FKFun.ShowNum(Id,"系统参数错误，请刷新页面！")
	Sqlstr="Select Fk_Vote_Id From [Fk_Vote] Where Fk_Vote_Id=" & Id
	Rs.Open Sqlstr,Conn,1,3
	If Not Rs.Eof Then
		Application.Lock()
		Rs.Delete()
		Application.UnLock()
		Response.Write("ok")
	Else
		Response.Write("要删除的投票不存在！")
	End If
	Rs.Close
End Sub

'==============================
'函 数 名：VoteLabel
'作    用：获取轮换调用代码
'==============================
Sub VoteLabel()
	Id=Trim(Request.QueryString("Id"))
%>
<div id="title">获取调用代码</div>
<div id="box">
	<table width="95%" border="1" bordercolor="#CCCCCC" align="center" cellpadding="0" cellspacing="0">
        <tr>
        	<td height="30" align="center">调用代码</td>
       	</tr>
        <tr>
            <td height="30">&nbsp;&nbsp;<input type="text" class="input" size="100" value="&lt;script type=&quot;text/javascript&quot; src=&quot;{$SiteDir$}Plugin/Vote/Vote.asp?Type=1&Id=<%=Id%>&quot;&gt;&lt;/script&gt;" />&nbsp;调用代码</td>
        </tr>
	</table>
</div>
<div id="bottom">
	<input type="button" onclick="dialogClose();" class="button" name="button" id="button" value="关 闭" />
</div>
<%
End Sub

Call FKFun.PageEnd()
%>
